﻿using System;
using System.DHTML;
using Sys;
using Sys.UI;
using Sys.Mvc;

using JQuerySharp;
using VietPublisher.Scripts.Resources;

static public class SC_Driver
{
    static public RegularExpression IdCardNo1 = new RegularExpression(@"^\d{6}$");
    static public RegularExpression IdCardNo2 = new RegularExpression(@"^\d{7}$");
    public static string ControllerUrl = "Driver";


    #region Driver Info

    public static void SaveDriver()
    {
        
        Dictionary form = (Dictionary)(object)Document.GetElementById("createDriver");
     
        UIHelper.SubmitAjax(form, "POST", null,
        new MvcCallback(delegate(AjaxContext context)
        {

            Script.Alert(Common.OperationSuccess);
            //----- return list-----

            Script.Literal("onRefresh();");
            
        }),
        new MvcCallback(delegate(AjaxContext context)
        {
            Script.Alert(Common.OperationFailed);
        }));

    }


    public static void OpenDriverInfoDetail(int DriverID)
    {
        //Utils.SetInputValue("DriverID", DriverID.ToString());

        string href = SC_Common.BasePath + ControllerUrl + string.Format("/DriverDetail?DriverID={0}&dt={1}", DriverID, new DateTime());
        UIHelper.LoadAjax(href, "headerView", null, null);
    }


    public static void OpenDriverDetail(int DriverID)
    {
        //Utils.SetInputValue("DriverID", DriverID.ToString());

        string href = SC_Common.BasePath + ControllerUrl + string.Format("/DriverDetail?DriverID={0}&dt={1}", DriverID, new DateTime());
        UIHelper.LoadAjax(href, "headerView", null, null);

        

        //string href2 = SC_Common.BasePath + ControllerUrl + string.Format("/OpenListCardHistory?DriverID={0}&dt={1}", DriverID, new DateTime());
        //UIHelper.LoadAjax(href2, "ViewContent", null, null);
        OpenCardHistoryList();
        

    }


    public static void OpenUpdate()
    {
        string DriverID = Utils.GetInputValue("DriverID").ToString();

       string href = SC_Common.BasePath + ControllerUrl + string.Format("/DriverUpdate?DriverID={0}&dt={1}", DriverID, new DateTime());
       UIHelper.LoadAjax(href, "headerView", null, null);
       
    }


    public static void OpenDelete()
    {
        string DriverID = Utils.GetInputValue("DriverID").ToString();
        //string href = SC_Common.BasePath + ControllerUrl + string.Format("/DriverUpdate?DriverID={0}&dt={1}", DriverID, new DateTime());
        // UIHelper.LoadAjax(href, "headerView", null, null);


        if (Script.Confirm(Common.DeleteConfirm))
        {
            string href = SC_Common.BasePath + ControllerUrl + string.Format("/DeleteInfo?DriverID={0}&dt={1}", DriverID, new DateTime());
            UIHelper.LoadAjax(href, "headerView", new MvcCallback(delegate(AjaxContext context)
            {
                if (context.request.Executor.ResponseData != "Error")
                {
                    Script.Alert(Common.DeleteMessageComplete);
                    Script.Literal("onRefresh();");
                }
                else
                {
                    Script.Alert(Common.DeleteMessageFail);
                }
            }), null);
        }


    }




    public static void OpenAddnew()
    {
        //string DriverID = Utils.GetInputValue("DriverID").ToString(); 
        string href = SC_Common.BasePath + ControllerUrl + string.Format("/CreateDriver?dt={0}", new DateTime());
        UIHelper.LoadAjax(href, "headerView", null, null);
    }
    #endregion

    public static void OpenCardHistoryList()
    {
        
        string DriverID = Utils.GetInputValue("DriverID");       
        string href = SC_Common.BasePath + ControllerUrl + string.Format("/OpenListCardHistory?DriverID={0}&dt={1}", DriverID, new DateTime());
        UIHelper.LoadAjaxNullEvent(href, "ViewContent", null);
    }

    public static void SearchDriverChargeHistory()
    {
        string fromDate = Utils.GetInputValue("from_Date");
        string toDate = Utils.GetInputValue("to_Date");
        string DriverID = Utils.GetInputValue("DriverID");

        string href = SC_Common.BasePath + ControllerUrl + string.Format("/OpenListCardHistory?from_Date={0}&to_Date={1}&DriverID={2}&dt={3}", fromDate, toDate, DriverID, new DateTime());
        UIHelper.LoadAjaxNullEvent(href, "ViewContent", null);

    }

    public static void openListCardbyDate(string id, string UseDate)
    {
        string href = SC_Common.BasePath + ControllerUrl + string.Format("/OpenListCardOneDate?UseDate={0}&DriverID={1}&dt={2}", UseDate, id, new DateTime());
        UIHelper.LoadAjaxNullEvent(href, "Content_Right", null);

    }



}
